﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Etapas.ascx.cs" Inherits="CustomControls_Etapas" %>
<h2 class="pagetitle"><asp:Literal runat="server" ID="ltrTitle" ></asp:Literal></h2>
<div class="column1-unit">
    <div class="form">
        <div class="required-message">Los campos indicados con <span class="required-mark">*</span> son requeridos</div>
        <fieldset><legend>&nbsp;Detalles de la Etapa&nbsp;</legend>
            <div class="field-line">
                <asp:Label runat="server" CssClass="left" ID="lblName" AssociatedControlID="txtName" Text="<span class='required-mark'>*</span> Nombre"></asp:Label>
                <asp:TextBox ID="txtName" CssClass="field" runat="server" Text=''  MaxLength="255"></asp:TextBox>
                <asp:RequiredFieldValidator ID="FNvalidator" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                    ControlToValidate="txtName" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
            </div>
            <div class="field-line">
                <asp:Label runat="server" CssClass="left" ID="lblDescription" AssociatedControlID="txtDescription" Text="&nbsp;&nbsp;&nbsp;Observaci&oacute;n"></asp:Label>
                <asp:TextBox ID="txtDescription" CssClass="field" runat="server"  TextMode="MultiLine"></asp:TextBox>
            </div>
            <div class="field-line">
                <asp:Label runat="server" CssClass="left" ID="lblTemp" AssociatedControlID="txtTemperature" Text="<span class='required-mark'>*</span> Tempeatura"></asp:Label>
                <asp:TextBox ID="txtTemperature" CssClass="short-field" runat="server" MaxLength="3"></asp:TextBox> &deg;C
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                    ControlToValidate="txtTemperature" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
                <asp:CompareValidator ID="CompareValidator1" runat="server" Operator="DataTypeCheck" Type="Integer" 
                    ControlToValidate="txtTemperature" Display="Dynamic" ForeColor="Red" ErrorMessage="Ingrese un valor entero" />
            </div>
            <div class="field-line">
                <asp:Label runat="server" CssClass="left" ID="lblTime" AssociatedControlID="txtTime" Text="<span class='required-mark'>*</span> Tiempo"></asp:Label>
                <asp:TextBox ID="txtTime" CssClass="short-field" runat="server" MaxLength="5"></asp:TextBox> Min
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                    ControlToValidate="txtTime" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
                <asp:CompareValidator ID="CompareValidator2" runat="server" Operator="DataTypeCheck" Type="Integer" 
                    ControlToValidate="txtTime" Display="Dynamic" ForeColor="Red" ErrorMessage="Ingrese un valor entero" />
            </div>
            <div class="field-line">
                <asp:Label runat="server" CssClass="left" ID="lblWater" AssociatedControlID="txtWater" Text="<span class='required-mark'>*</span> Agua"></asp:Label>
                <asp:TextBox ID="txtWater" CssClass="short-field" runat="server" MaxLength="5"></asp:TextBox> Lt
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                    ControlToValidate="txtWater" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
                <asp:CompareValidator ID="CompareValidator3" runat="server" Operator="DataTypeCheck" Type="Integer" 
                    ControlToValidate="txtWater" Display="Dynamic" ForeColor="Red" ErrorMessage="Ingrese un valor entero" />
            </div>
            <div class="field-line">
                <asp:Label runat="server" CssClass="left" ID="lblOrder" AssociatedControlID="drdOrder" Text="&nbsp;&nbsp;&nbsp;Orden"></asp:Label>
                <asp:DropDownList runat="server" ID="drdOrder" CssClass="medium-field"></asp:DropDownList>
            </div>
        </fieldset>
        <fieldset class="fieldset-products">
            <legend>&nbsp;Productos&nbsp;</legend>
            <asp:ScriptManager ID="ScriptManager2" runat="server" />
            <asp:UpdatePanel runat="server" id="UpdatePanel1">
                <ContentTemplate>
                    <asp:Panel runat="server" ID="divFilter" DefaultButton="btnSearch" CssClass="internal-filter" >
                        <asp:TextBox ID="txtSearchTerm" CssClass="field" runat="server" MaxLength="255"></asp:TextBox>
                        <asp:ImageButton class="button-filter" runat="server" onclick="btnSearch_Click" CausesValidation="false" ID="btnSearch" AlternateText="Buscar" ToolTip="Buscar" 
                            ImageUrl="~/img/search-icon.png"/>
                    </asp:Panel>
                    <asp:ObjectDataSource ID="dsProducts" runat="server" TypeName="BLLStages" SelectMethod="GetUnassignedProducts"
                        EnablePaging="true" SelectCountMethod="GetUnassignedProductsRowCount" StartRowIndexParameterName="startRow"
                        MaximumRowsParameterName="pageSize" SortParameterName="sortColumns">        
                        <SelectParameters>
                            <asp:SessionParameter Name="guid" SessionField="uniqueId"/>
                            <asp:ControlParameter ControlID="txtSearchTerm" DefaultValue="" Name="filter" PropertyName="Text" Type="String" />
                        </SelectParameters>              
                    </asp:ObjectDataSource>
                    <asp:gridview ID="grdProductos" DataSourceID="dsProducts" runat="server" AutoGenerateColumns="False" 
                        EmptyDataText="No existen productos" BorderStyle="None" AlternatingRowStyle-CssClass="row-alternation"
                        CssClass="grid-add-edit" CellPadding="0"  Width="100%" OnSorting="grdAssigned_Sorting" OnPageIndexChanging="grdAssigned_PageIndexChanging" >
                        <HeaderStyle BackColor="#26688C" ForeColor="White" />
                        <PagerStyle CssClass="pagination" />
                        <Columns>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    <asp:CheckBox runat="server" ID="chkAll" CssClass="checkAll" />
                                </HeaderTemplate>
                                <ItemTemplate>  
                                    <asp:HiddenField runat="server" ID="hdnProductId" Value='<%#Eval("Id")%>' />
                                    <asp:CheckBox runat="server" ID="chkAssignProduct" CssClass="checkSingle checkToAssign" />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" Width="30px" CssClass="td-check" />
                            </asp:TemplateField>
                            <asp:BoundField DataField="Name" HeaderText="Nombre" SortExpression="name" HeaderStyle-HorizontalAlign="Left" >
                            </asp:BoundField>  
                            <asp:TemplateField HeaderText="Cantidad">
                                <ItemTemplate>  
                                    <asp:TextBox runat="server" ID="txtQuantity" CssClass="qyt" MaxLength="10" Width="70px" />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Observaci&oacute;n">
                                <ItemTemplate>  
                                    <asp:TextBox runat="server" ID="txtObservation" TextMode="MultiLine" Width="150px" />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                        </Columns>
                    </asp:gridview>
                    <div class="filed-line-buttons">
                        <asp:Button ID="btnAdd" runat="server" CssClass="but3" OnClick="btnAdd_Click" OnClientClick="return validate();" Text="Agregar" CausesValidation="False"/>
                        <asp:Button ID="btnRemove" runat="server" CssClass="but3" OnClick="btnRemove_Click" Text="Eliminar" CausesValidation="False"/>
                    </div>
                    <asp:ObjectDataSource ID="dsAssignedProducts" runat="server" TypeName="BLLStages" SelectMethod="GetAssignedProducts"
                        EnablePaging="true" SelectCountMethod="GetAssignedProductsRowCount" StartRowIndexParameterName="startRow"
                        MaximumRowsParameterName="pageSize" SortParameterName="sortColumns">        
                        <SelectParameters>
                            <asp:SessionParameter Name="guid" SessionField="uniqueId"/>
                        </SelectParameters>              
                    </asp:ObjectDataSource>
                    <asp:gridview ID="grdAssigned" DataSourceID="dsAssignedProducts" runat="server" AutoGenerateColumns="False" 
                        EmptyDataText="No existen productos asignados" BorderStyle="None" AlternatingRowStyle-CssClass="row-alternation"
                        CssClass="grid-add-edit" CellPadding="0"  Width="100%" OnPageIndexChanging="grdAssigned_PageIndexChanging" OnSorting="grdAssigned_Sorting" >
                        <HeaderStyle BackColor="#26688C" ForeColor="White" />
                        <PagerStyle CssClass="pagination" />
                        <Columns>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    <asp:CheckBox runat="server" ID="chkAll" CssClass="checkAll" />
                                </HeaderTemplate>
                                <ItemTemplate>  
                                    <asp:HiddenField runat="server" ID="hdnProductId" Value='<%#Eval("Id")%>' />
                                    <asp:CheckBox runat="server" ID="chkAssignProduct" CssClass="checkSingle" />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" Width="30px" CssClass="td-check" />
                            </asp:TemplateField>
                            <asp:BoundField DataField="Name" HeaderText="Nombre" SortExpression="name" HeaderStyle-HorizontalAlign="Left" >
                            </asp:BoundField>  
                            <asp:TemplateField HeaderText="Cantidad">
                                <ItemTemplate>  
                                    <asp:TextBox runat="server" ID="txtQuantity" MaxLength="10" Width="70px" Text='<%# getQuantity(Eval("Quantity")) %>' />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Observaci&oacute;n">
                                <ItemTemplate>  
                                    <asp:TextBox runat="server" ID="txtObservation" TextMode="MultiLine" Width="150px" Text='<%# getObservation(Eval("Observation")) %>' />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                        </Columns>
                    </asp:gridview>
                </ContentTemplate>
            </asp:UpdatePanel>
            <em>La catidad de producto debe ser introducida por cada kilogramo de pantalones.</em><br />
            <em>Las catidades deben ser expresadas en gramos/mililitros.</em>
        </fieldset>
        <div class="buttons-actions">
            <asp:Button runat="server" ID="btnSave" OnClick="btnSave_Click" Text="Guardar" />
            <asp:Button runat="server" ID="btnCancel" OnClick="btnCancel_Click" CausesValidation="false" Text="Cancelar" />
        </div>
        <div class="clear"></div>
    </div>  
</div>  
<script type="text/javascript">
    var showMessage = false;

    $(document).ready(function () {
        $("span.checkAll input, span.checkAllAssigned input").live("click", function (event) {
            var checked = $(this).attr('checked');
            $(this).parent().parent().parent().siblings().each(function (event) {
                $(this).find('input').attr('checked', checked);
            })
        });
        $("span.checkSingle input").live("click", function (event) {
            var checked = $(this).attr('checked');
            if (!checked) {
                $("span.checkAll input").removeAttr('checked')
            } else {
                c = true
                $("span.checkSingle input").each(function (event) {
                    if (!$(this).attr('checked'))
                        c = false
                })
                if (c)
                    $("span.checkAll input").attr('checked', 'true')
            }
        });
        $("#<%=btnRemove.ClientID %>").live("click", function (event) {
            show();
        })
        $("#<%=grdProductos.ClientID %> a").live("click", function (event) {
            show();
        })
        $("#<%=grdAssigned.ClientID %> a").live("click", function (event) {
            show();
        })
        $("#<%=btnSearch.ClientID %>").live("click", function (event) {
            show();
        })
    });

    
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandle);
    function endRequestHandle(sender, Args) {
        $(".progress-dialog").dialog('close')
    }
    function show() {
        $(".progress-dialog").dialog({
            maxWidth: 400,
            maxHeight: 150,
            height: 150,
            width: 400,
            resizable: false,
            modal: true,
            autoOpen: true,
        });
        $(".ui-dialog-titlebar").hide();
    }
    function validate()
    {
        $(".required-grid").remove()
        v = true;
        $(".qyt").each(function () {
            var valid = ($(this).val().match(/^-?\d*(\.\d+)?$/));
            if (!valid) {
                $(this).parent().append("<span class='required-grid'>Valor Inv&aacute;lido</span>")
                v = false;
            }
        })
        checked = false;
        $(".checkToAssign input:checkbox:checked").each(function () {
            checked = true;
        });
        if (v && checked)
            show();
        else
            v = false;
        return v;
    }
</script>
<div class="progress-dialog" style="display:none">
    <div style="margin: 30px auto 0px 140px;">
        <img src="<%= this.ResolveUrl("~") %>img/loading.gif" alt="In Progress"/>&nbsp;&nbsp;Cargando...
    </div>
</div>